package com.glasses.manage.utils;

import java.util.List;

/**
 * 页面分页
 * @author heiqi_yan
 *
 * @param <T>
 */
public class PageInfo<T extends Object> implements java.io.Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 6686230521816848694L;
	/*当前页数*/
	private int currentPage =1;
	/*每页大小*/
	private int pageSize = 10;
	/*项目总数*/
	private int totalItem;
	/*当前页项目对象集合*/
	private List<T> pageItems;

	private String pageErrorInfo;

    /**
     * 是否导出。
     * false：分页控件正常进行分页
     * true：不分页查询全部，但是会校验count不能超过60000
     */
	private boolean isExport = false;
	
	public int getCurrentPage() {
		return currentPage>0?currentPage:1;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	/*获取总页数*/
	public int getTotalPage() {
		return totalItem/pageSize + (totalItem%pageSize==0?0:1);
	}
	
	public int getTotalItem() {
		return totalItem;
	}
	public void setTotalItem(int totalItem) {
		this.totalItem = totalItem;
	}
	public List<T> getPageItems() {
		return pageItems;
	}
	public void setPageItems(List<T> pageItems) {
		this.pageItems = pageItems;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getStartItem(){
		return (getCurrentPage()-1)*getPageSize();
	}

    public String getPageErrorInfo() {
        return pageErrorInfo;
    }

    public void setPageErrorInfo(Exception e) {
        setPageErrorInfo(e.getMessage());
    }

    public void setPageErrorInfo(String pageErrorInfo) {
        this.pageErrorInfo = pageErrorInfo;
    }

    public boolean isExport() {
        return isExport;
    }

    public void setExport(boolean export) {
        isExport = export;
    }
}
